package com.example.smartlearning.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.smartlearning.dao.GuanZhuDao;
import com.example.smartlearning.entity.GuanZhuEntity;
import com.example.smartlearning.entity.ResultEntity;
import com.example.smartlearning.service.GuanZhuService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class GuanZhuServiceImpl extends ServiceImpl<GuanZhuDao, GuanZhuEntity> implements GuanZhuService {

    @Resource
    GuanZhuDao guanZhuDao;

    private static final Logger logger = LoggerFactory.getLogger(GuanZhuServiceImpl.class);//日志。getLogger需要传入当前的类名

    /**
     * 查看所有关注者的发帖
     *
     * @param id 当前登录用户id
     * @return 返回
     */
    @Override
    public String selectAllById(int id) {
        try {
            return ResultEntity.success(guanZhuDao.selectAllById(id));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }

    /**
     * 新增关注
     *
     * @param userId 用户id
     * @param id     被关注者id
     * @return 返回
     */
    @Override
    public String addNew(int userId, int id) {
        try {
            return ResultEntity.success(guanZhuDao.addNew(userId, id));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }

    /**
     * 取消关注
     *
     * @param userId 用户id
     * @param id     id
     * @return 返回
     */
    @Override
    public String cancelById(int userId, int id) {
        try {
            return ResultEntity.success(guanZhuDao.cancelById(userId, id));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }


}
